package com.majie.aop.notspring;

import com.majie.aop.annotation.LogMethodBeforeAdvice;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;

/**
 * ProxyFactory 它和Spring容器没啥关系，可议直接创建代理来使用
 */
public class MyProxyFactory {

	public static void main(String[] args) {
		ProxyFactory proxyFactory = new ProxyFactory(new Person());

		// 添加两个Advise，一个匿名内部类表示
		proxyFactory.addAdvice((AfterReturningAdvice) (returnValue, method, args1, target) ->
				System.out.println("AfterReturningAdvice method=" + method.getName()));
		proxyFactory.addAdvice(new LogMethodBeforeAdvice());

		Person proxy = (Person) proxyFactory.getProxy();
		proxy.run();
	}
}
